package com.codding.springboot_mybatisdemo.mapper;

import com.codding.springboot_mybatisdemo.entity.Users;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("SELECT user_id AS userId, user_name AS userName, user_tel AS userTel, user_score AS userScore, user_sex AS userSex FROM users")
    List<Users> selectAll();

    List<Users> selectByDynamic(
            @Param("id") Integer userId,
            @Param("name") String userName,
            @Param("tel") String userTel,
            @Param("sex") String userSex,
            @Param("min") Integer minScore,
            @Param("max") Integer maxScore
    );

    @Delete("DELETE FROM users WHERE user_id = #{userId}")
    int deleteUserById(@Param("userId") Integer userId);

    // 新增插入用户的方法
    @Insert("INSERT INTO users (user_id, user_name, user_score, user_tel, user_sex) " +
            "VALUES (#{userId}, #{userName}, #{userScore}, #{userTel}, #{userSex})")
    int insertUser(Users user);  // 插入用户数据
}
